Imports System.Data.SqlClient
Imports System.Security.AccessControl
Imports System.IO

Public Class frmUtilityBackupRestore
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        gblnTimerTick = True
        Me.Close()
    End Sub

    Private Sub btnBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackup.Click
        'Dim backup As SQLDMO.Backup
        'Dim sqlserver As SQLDMO.SQLServer
        Dim strQuery As String

        Try
            If txtBackupFolder.Text = "" Then
                MessageBox.Show("Specify backup location!", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtBackupFolder.Focus()
                Exit Sub
            ElseIf Trim(txtSQLBackupFileName.Text) = "" Then
                MessageBox.Show("Specify a name for the backup!", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtBackupFolder.Focus()
                Exit Sub
            End If



            'backup = New SQLDMO.BackupClass()
            'sqlserver = New SQLDMO.SQLServerClass()

            'If Val(GetRegistryValue("Authentication")) = 1 Then
            '    sqlserver.LoginSecure = True
            '    sqlserver.Connect(gstrDataSource)
            'Else
            '    sqlserver.LoginSecure = False
            '    sqlserver.Connect(gstrDataSource, gstrSQLUSER_ID, gstrSQLPASS_WORD)
            'End If

            'backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database

            'backup.Database = gstrDatabase

            'backup.Files = txtBackupFolder.Text & txtSQLBackupFileName.Text

            'backup.BackupSetName = gstrDatabase

            'backup.BackupSetDescription = "Database backup description"

            'backup.Initialize = True

            'backup.SQLBackup(sqlserver)

            gconWebPlusMed.Close()


            Dim dInfo As DirectoryInfo = Directory.GetParent(txtBackupFolder.Text)
            If Not dInfo Is Nothing Then
                Call AddDirectorySecurity(dInfo.FullName, Environment.UserDomainName & "\" & Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow)
            Else
                MessageBox.Show("Do Not BackUp to the Desktop or Root Directory.", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtBackupFolder.Focus()
                Exit Sub
            End If
            gblnTimerTick = False : lblWait.Visible = True : Application.DoEvents()

            gconWebPlusMed.ConnectionString = Replace(gstrConnectionString, gstrDatabase, "master")
            gconWebPlusMed.Open()

            strQuery = "Execute dbo.BackupRestore 0,'" & txtBackupFolder.Text & txtSQLBackupFileName.Text & "'"
            Call ProcExecute(strQuery)

            lblWait.Visible = False : Application.DoEvents()
            MessageBox.Show("Database backed up successfully.", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Information)
            SetRegistryValue("Backup Path", txtBackupFolder.Text)

        Catch ex As Exception
            lblWait.Visible = False : Application.DoEvents()
            If ex.Message.Contains("Access is denied") Then
                MessageBox.Show("Cannot backup the database to '" & txtBackupFolder.Text & "'." & vbCrLf & "This folder or the root folder doesnot have access permission.", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If


            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        Finally
            gconWebPlusMed.Close()
            gconWebPlusMed.ConnectionString = gstrConnectionString
            gconWebPlusMed.Open()
            'gblnTimerTick = True
        End Try
    End Sub

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        Try
            ' First create a FolderBrowserDialog object
            Dim FolderBrowserDialog1 As New FolderBrowserDialog
            Dim strPath As String = GetRegistryValue("Backup Path")

            strPath = IIf(txtBackupFolder.Text = "", IIf(strPath <> "", strPath, "C:\"), txtBackupFolder.Text)

            ' Then use the following code to create the Dialog window
            ' Change the .SelectedPath property to the default location
            With FolderBrowserDialog1
                ' Desktop is the root folder in the dialog.
                .RootFolder = Environment.SpecialFolder.Desktop
                ' Select the C:\Windows directory on entry.
                .SelectedPath = strPath
                ' Prompt the user with a custom message.
                .Description = "Select the destination directory"
                If .ShowDialog = Windows.Forms.DialogResult.OK Then
                    ' Display the selected folder if the user clicked on the OK button.
                    txtBackupFolder.Text = .SelectedPath & IIf(Strings.Right(.SelectedPath, 1) <> "\", "\", "")
                End If
                .Dispose()
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub rgBackupRestore_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rgBackupRestore.SelectedIndexChanged
        Select Case rgBackupRestore.SelectedIndex
            Case 0
                grpSQLBackup.Visible = True
                grpSQLRestore.Visible = False
                txtBackupFolder.Text = GetRegistryValue("Backup Path")
                txtSQLBackupFileName.Text = "BK-" & gstrDatabase & "-" & gdtCurrentDate.ToString("MMM") & "_" & Format(gdtCurrentDate, "dd") & ".BAK"
                lblBackup.Text = "Backup of Database (" & gstrDatabase & ")"
            Case 1
                grpSQLBackup.Visible = False
                grpSQLRestore.Visible = True
                txtSQLRestorationFileLocation.Text = ""
                lblRestore.Text = "Complete Restoration of Database (" & gstrDatabase & ")"
        End Select
    End Sub

    Private Sub frmUtilityBackupRestore_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.Control = True And e.Shift = True Then
            lblDetach.Visible = True
        Else
            lblDetach.Visible = False
        End If
    End Sub

    Private Sub frmUtilityBackupRestore_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        lblDetach.Visible = False
    End Sub

    Private Sub frmUtilityBackupRestore_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strConnection As String
        Dim tempCon As SqlConnection = Nothing
        Try


            SetImageControl(Me)

            rgBackupRestore_SelectedIndexChanged(Nothing, Nothing)

            btnBackup.Image = mdiMain.imgFormIcons.Images(1)
            btnRestore.Image = mdiMain.imgFormIcons.Images(2)

            Me.Icon = System.Drawing.Icon.FromHandle(CType(mdiMain.imgMDIForm.Images(20), Bitmap).GetHicon())

            'Dim strSQL As String
            strConnection = "Persist Security Info=" & GetRegistryValue("Persist Security Info") & ";"
            strConnection = strConnection & "Initial Catalog=master;"
            strConnection = strConnection & "Data Source=" & gstrDataSource
            If Val(GetRegistryValue("Authentication")) = 0 Then
                strConnection = strConnection & ";User ID=" & gstrSQLUSER_ID & ";"
                strConnection = strConnection & "PWD=" & gstrSQLPASS_WORD
            Else
                strConnection = strConnection & ";Integrated Security=SSPI"
            End If

            tempCon = New SqlConnection(strConnection)
            tempCon.Open()
            Dim strQuery As String
            strQuery = "select name from sysObjects where type='P' and name ='BackupRestore'"
            gcmdWebPlusMed = New SqlCommand(strQuery, tempCon)
            Dim obj As Object = gcmdWebPlusMed.ExecuteScalar()
            If obj Is Nothing Then
                strQuery = "Create PROCEDURE [dbo].[BackupRestore] " & _
                                            "@blncheck as BIT,	" & _
                                            "@filename as Varchar(100)	" & _
                                            "AS " & _
                                            "BEGIN " & _
                                            "	Declare @Querys  AS VARCHAR(max) " & _
                                            "	IF @blncheck=0 " & _
                                            "	BEGIN " & _
                                            "	SET @Querys='BACKUP DATABASE WebMed TO DISK=''' + @filename + ''''; " & _
                                            "	END " & _
                                            "	ELSE " & _
                                            "	BEGIN " & _
                                            "	SET @Querys='RESTORE DATABASE WebMed FROM DISK=''' + @filename + ''''; " & _
                                            "	END " & _
                                            "	Exec(@Querys) " & _
                                            "END "

                gcmdWebPlusMed = New SqlCommand(strQuery, tempCon)
                gcmdWebPlusMed.ExecuteNonQuery()

            End If
            Dim strPath As String = GetRegistryValue("Backup Path")
            If strPath = "" Then
                strPath = "C:\EnvironMed\WebMedDatabaseBackUp"
                If System.IO.Directory.Exists(strPath) Then
                    System.IO.Directory.CreateDirectory(strPath)
                End If
                strPath = strPath & "\"
            End If
            txtBackupFolder.Text = strPath
            tempCon.Close()
        Catch ex As Exception
            If tempCon Is Nothing Then
            Else
                If tempCon.State = ConnectionState.Open Then
                    tempCon.Close()
                End If
            End If
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub txtBackupFolder_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBackupFolder.GotFocus
        txtBackupFolder.SelectAll()
    End Sub

    Private Sub txtSQLBackupFileName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSQLBackupFileName.GotFocus
        txtSQLBackupFileName.SelectAll()
    End Sub

    Private Sub btnRestoreBrowse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRestoreBrowse.Click
        Try
            ' First create a FolderBrowserDialog object
            Dim FileBrowserDialog1 As New OpenFileDialog
            Dim strPath As String = GetRegistryValue("Backup Path")

            strPath = IIf(txtBackupFolder.Text = "", IIf(strPath <> "", strPath, "C:\"), txtBackupFolder.Text)

            With FileBrowserDialog1
                .Filter = "BAK Files(*.bak)|*.bak|All Files(*.*)|*.*"
                .InitialDirectory = strPath
                .Multiselect = False
                .Title = "Select backup of " & gstrDatabase
                If .ShowDialog = Windows.Forms.DialogResult.OK Then
                    txtSQLRestorationFileLocation.Text = .FileName
                End If
                .Dispose()
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub btnRestore_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRestore.Click
        'Dim restore As SQLDMO.Restore
        'Dim sqlserver As SQLDMO.SQLServer
        Dim rdProcess As SqlDataReader
        Dim cmdProcess As SqlCommand
        Dim strMessage As String = ""
        Dim strQuery As String = ""

        Try
            gblnTimerTick = False
            If txtSQLRestorationFileLocation.Text = "" Then
                MessageBox.Show("Select a backup file!", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtSQLRestorationFileLocation.Focus()
                gblnTimerTick = True
                Exit Sub
            End If

            lblWait.Visible = True : Application.DoEvents()

            'restore = New SQLDMO.Restore
            'sqlserver = New SQLDMO.SQLServer

            'If Val(GetRegistryValue("Authentication")) = 1 Then
            '    sqlserver.LoginSecure = True
            '    sqlserver.Connect(gstrDataSource)
            'Else
            '    sqlserver.LoginSecure = False
            '    sqlserver.Connect(gstrDataSource, gstrSQLUSER_ID, gstrSQLPASS_WORD)
            'End If

            gconWebPlusMed.Close()

            gconWebPlusMed.ConnectionString = Replace(gstrConnectionString, gstrDatabase, "master")
            gconWebPlusMed.Open()

            cmdProcess = New SqlCommand("select * from sysprocesses where dbid=db_id('" & gstrDatabase & "')", gconWebPlusMed)

            rdProcess = cmdProcess.ExecuteReader
            Do While rdProcess.Read
                strMessage = strMessage & IIf(strMessage <> "", vbCrLf, "") & vbCrLf & _
                            rdProcess.Item("spid") & vbTab & rdProcess.Item("hostname") & vbTab & _
                            rdProcess.Item("program_name") & vbTab & rdProcess.Item("loginame")
                strQuery = strQuery & IIf(strQuery <> "", ";", "") & "Kill " & rdProcess.Item("spid")
            Loop
            If rdProcess.HasRows = True Then
                rdProcess.Close() : rdProcess = Nothing
                If MessageBox.Show("The below process(es) needs to be terminated before database restore" & vbCrLf & _
                    "PID" & vbTab & "PC Name" & vbTab & "Program Name" & vbTab & "Login ID" & vbCrLf & strMessage & vbCrLf & vbCrLf & _
                    "Are you sure to terminate the process(es)", gstrMessage, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

                    cmdProcess = New SqlCommand(strQuery, gconWebPlusMed)
                    cmdProcess.ExecuteNonQuery()
                Else
                    gblnTimerTick = True
                    gconWebPlusMed.Close()
                    gconWebPlusMed.ConnectionString = gstrConnectionString
                    gconWebPlusMed.Open()
                    Exit Sub
                End If
            End If
            'restore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database

            'restore.Database = gstrDatabase

            'restore.Files = txtSQLRestorationFileLocation.Text
            'restore.ReplaceDatabase = True

            'restore.FileNumber = 1

            'restore.SQLRestore(sqlserver)

            Dim dInfo As DirectoryInfo = Directory.GetParent(txtSQLRestorationFileLocation.Text)
            If Not dInfo Is Nothing Then
                Call AddDirectorySecurity(dInfo.FullName, Environment.UserDomainName & "\" & Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow)
            End If

            strQuery = "Execute dbo.BackupRestore 1,'" & txtSQLRestorationFileLocation.Text & "'"
            Call ProcExecute(strQuery)

            lblWait.Visible = False : Application.DoEvents()
            MessageBox.Show("Database restored successfully", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Information)

        Catch ex As Exception
            lblWait.Visible = False : Application.DoEvents()
            If ex.Message.Contains("A transport-level") Then
                MessageBox.Show("Cannot restore the backup", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        Finally
            gconWebPlusMed.Close()
            gconWebPlusMed.ConnectionString = gstrConnectionString
            gconWebPlusMed.Open()
            'gblnTimerTick = True
        End Try
    End Sub

    Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
        ' Create a new DirectoryInfoobject.
        Dim dInfo As New DirectoryInfo(FileName)

        ' Get a DirectorySecurity object that represents the 
        ' current security settings.
        Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl(AccessControlSections.Access)

        ' Add the FileSystemAccessRule to the security settings. 
        Dim myRule As FileSystemAccessRule
        myRule = New FileSystemAccessRule(Account, Rights, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)
        'myRule = New FileSystemAccessRule(Account, Rights, ControlType)

        dSecurity.AddAccessRule(myRule)
        dSecurity.SetAccessRule(myRule)
        ' Set the new access settings.
        dInfo.SetAccessControl(dSecurity)

    End Sub

    ' Removes an ACL entry on the specified directory for the specified account.
    Sub RemoveDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
        ' Create a new DirectoryInfo object.
        Dim dInfo As New DirectoryInfo(FileName)

        ' Get a DirectorySecurity object that represents the 
        ' current security settings.
        Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl(AccessControlSections.Access)

        ' Add the FileSystemAccessRule to the security settings. 
        Dim myRule As FileSystemAccessRule
        myRule = New FileSystemAccessRule(Account, Rights, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)
        'myRule = New FileSystemAccessRule(Account, Rights, ControlType)

        dSecurity.RemoveAccessRule(myRule)
        dSecurity.SetAccessRule(myRule)

        ' Set the new access settings.
        dInfo.SetAccessControl(dSecurity)

    End Sub

    Private Sub lblDetach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblDetach.Click
        '    Dim strMessage As String = ""
        '    Dim strQuery As String = ""
        '    Dim sqlserver As SQLDMO.SQLServer
        '    Dim rdProcess As SqlDataReader
        '    Dim cmdProcess As SqlCommand


        '    If MessageBox.Show("Are you sure to detach databases", gstrMessage, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.No Then
        '        Exit Sub
        '    End If

        '    Try
        '        lblWait.Visible = True : Application.DoEvents()
        '        sqlserver = New SQLDMO.SQLServer

        '        If Val(GetRegistryValue("Authentication")) = 1 Then
        '            sqlserver.LoginSecure = True
        '            sqlserver.Connect(gstrDataSource)
        '        Else
        '            sqlserver.LoginSecure = False
        '            sqlserver.Connect(gstrDataSource, gstrSQLUSER_ID, gstrSQLPASS_WORD)
        '        End If

        '        gconXtraINV.Close()

        '        gconXtraINV.ConnectionString = Replace(gstrConnectionString, gstrDatabase, "master")
        '        gconXtraINV.Open()

        '        'Detach gstrMasterDatabase
        '        cmdProcess = New SqlCommand("select * from sysprocesses where dbid=db_id('" & gstrMasterDatabase & "')", gconXtraINV)

        '        rdProcess = cmdProcess.ExecuteReader
        '        Do While rdProcess.Read
        '            strQuery = strQuery & IIf(strQuery <> "", ";", "") & "Kill " & rdProcess.Item("spid")
        '        Loop
        '        If rdProcess.HasRows = True Then
        '            rdProcess.Close() : rdProcess = Nothing
        '            cmdProcess = New SqlCommand(strQuery, gconXtraINV)
        '            cmdProcess.ExecuteNonQuery()
        '        End If

        '        strMessage = sqlserver.DetachDB(gstrMasterDatabase) '-- Perform the detach 

        '        'Detach gstrDatabase
        '        cmdProcess = New SqlCommand("select * from sysprocesses where dbid=db_id('" & gstrDatabase & "')", gconXtraINV)

        '        strQuery = ""

        '        rdProcess = cmdProcess.ExecuteReader
        '        Do While rdProcess.Read
        '            strQuery = strQuery & IIf(strQuery <> "", ";", "") & "Kill " & rdProcess.Item("spid")
        '        Loop
        '        If rdProcess.HasRows = True Then
        '            rdProcess.Close() : rdProcess = Nothing
        '            cmdProcess = New SqlCommand(strQuery, gconXtraINV)
        '            cmdProcess.ExecuteNonQuery()
        '        End If

        '        strMessage = sqlserver.DetachDB(gstrDatabase) '-- Perform the detach 

        '        MessageBox.Show("Database Detached", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Information)
        '        lblWait.Visible = False : Application.DoEvents()
        '        End

        '    Catch ex As Exception
        '        lblWait.Visible = False : Application.DoEvents()
        '        MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
        '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
        '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        '    End Try
    End Sub

    'Private Sub btnBackup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBackup.Click
    '    Dim backup As SQLDMO.Backup
    '    Dim sqlserver As SQLDMO.SQLServer

    '    Try
    '        If txtBackupFolder.Text = "" Then
    '            MessageBox.Show("Specify backup location!", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '            txtBackupFolder.Focus()
    '            Exit Sub
    '        ElseIf Trim(txtSQLBackupFileName.Text) = "" Then
    '            MessageBox.Show("Specify a name for the backup!", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '            txtBackupFolder.Focus()
    '            Exit Sub
    '        End If

    '        Dim dInfo As DirectoryInfo = Directory.GetParent(txtBackupFolder.Text)
    '        If dInfo Is Nothing Then
    '            MessageBox.Show("Do not BackUp to the Desktop or Root Directory.", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '            txtBackupFolder.Focus()
    '            Exit Sub
    '        End If

    '        lblWait.Visible = True : Application.DoEvents()

    '        backup = New SQLDMO.BackupClass()
    '        sqlserver = New SQLDMO.SQLServerClass()

    '        If Val(GetRegistryValue("Authentication")) = 1 Then
    '            sqlserver.LoginSecure = True
    '            sqlserver.Connect(gstrDataSource)
    '        Else
    '            sqlserver.LoginSecure = False
    '            sqlserver.Connect(gstrDataSource, gstrSQLUSER_ID, gstrSQLPASS_WORD)
    '        End If

    '        backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database

    '        backup.Database = gstrDatabase

    '        backup.Files = txtBackupFolder.Text & txtSQLBackupFileName.Text

    '        backup.BackupSetName = gstrDatabase

    '        backup.BackupSetDescription = "Database backup description"

    '        backup.Initialize = True

    '        backup.SQLBackup(sqlserver)

    '        lblWait.Visible = False : Application.DoEvents()
    '        MessageBox.Show("Database backed up successfully.", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Information)
    '        SetRegistryValue("Backup Path", txtBackupFolder.Text)

    '    Catch ex As Exception
    '        lblWait.Visible = False : Application.DoEvents()
    '        If ex.Message.Contains("Access is denied") Then
    '            MessageBox.Show("Cannot backup the database to '" & txtBackupFolder.Text & "'." & vbCrLf & "This folder or the root folder doesnot have access permission.", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        Else
    '            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
    '        End If
    '        AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
    '            Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
    '    End Try
    'End Sub
End Class